#!/usr/bin/env python
import gammu
import threading
import time
from Sms import *

class SmsSender(threading.Thread):
    def __init__(self, stateMachine, outQueue):
	threading.Thread.__init__(self)
	self._stateMachine = stateMachine
	self._outQueue = outQueue
    def sendMessage(self, messageToSend):
	print "SmsSender: sending message"
	self._stateMachine.SendSMS(messageToSend)
	print "SmsSender: message sent"
    def run(self):
	print "SmsSender: running"
	while 1:
	    msg = self._outQueue.get()
	    print "SmsSender: got message from queue"
	    self.sendMessage(msg)

def main():
    sm = gammu.StateMachine()
    sm.ReadConfig()
    sm.Init()
    smsSender = SmsSender(sm, None)
    msg = Sms("28458981", "SmsSender.py: test")
    print "sending..."
    smsSender.sendMessage(msg)
    print "...successfully sent"

if __name__=="__main__":
    print __name__
    main()

